package com.bigdata.bookinfo.mapper;

import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

public class Price_rDisMapper extends Mapper<LongWritable, Text, Text, IntWritable> {
    @Override
    protected void map(LongWritable key, Text value, Context context) throws InterruptedException, IOException {
        String[] line = value.toString().split("\t");
        String price_r = line[7];
        double l = -1;
        try {
            l = Double.parseDouble(price_r);
        } catch (Exception e) {
            return;
        }
        if (l<0){
            return;
        }
        if (l<=50.0){
            context.write(new Text("0~50"),new IntWritable(1));
        } else if (l <= 100.0) {
            context.write(new Text("51~100"),new IntWritable(1));
        } else if (l<=150.0) {
            context.write(new Text("101~150"),new IntWritable(1));
        }else {
            context.write(new Text("150以上"),new IntWritable(1));
        }
    }
}
